﻿using QunFaExpert;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Globalization;
using QunFaExpert.Data;
using WeiBeeCommon.Core;
using System.Threading;

namespace TestQunFaExpert
{
    
    
    /// <summary>
    ///This is a test class for RetweetExpertTest and is intended
    ///to contain all RetweetExpertTest Unit Tests
    ///</summary>
    [TestClass()]
    public class RetweetExpertTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for TweeterUrlToId
        ///</summary>
        [TestMethod()]
        public void TweeterUrlToIdTest()
        {
            RetweetExpert target = new RetweetExpert(); // TODO: Initialize to an appropriate value
            string url = @"http://weibo.com/1776491644/xpCPXhh1W";// "http://t.sina.com.cn/1644685685/wr4kImrltr";// http://weibo.com/1587267634/xn961DuBK
            string expected = "3361074934117044";// string.Empty; // TODO: Initialize to an appropriate value
            string actual;
            actual = (new TypedId(url)).id; ;
            Assert.AreEqual(expected, actual);
            List<string> a = new List<string>()
            {
                "3361109010638840","xpDIV2GbS" };
            //,"7510987001","xqLL74JY8","7328923203","3J4CXYkb4T","7368554725","5KD0W3YBYN0",
             //   "7405265679","3z4CYm701M","7412340075","3z4CYmmonO","7417924747","3J4CYmy51A","7417898739","3f4CYmvEch",
               // "7417861329","3f4CYmyz7s","7418000151","3f4CYmyKnQ","7417928361","3f4CYmA1pb"
            //};
            for (int i = 0; i < a.Count - 1; i += 2)
            {
                Assert.AreEqual(a[i], (new TypedId(string.Format(@"http://weibo.com/1776491644/{0}", a[i + 1])).id ));
            }
        }

        /// <summary>
        ///A test for StringToDateTime
        ///</summary>
        [TestMethod()]
        public void StringToDateTimeTest()
        {
            RetweetExpert target = new RetweetExpert(); // TODO: Initialize to an appropriate value
            string p = "Tue Oct 04 22:00:00 +0800 2011";
            DateTime expected = new DateTime(2011,10,4,22,0,0); // TODO: Initialize to an appropriate value
            DateTime actual;
            actual = target.StringToDateTime(p);           
            Assert.AreEqual(expected, actual);
            //http://msdn.microsoft.com/zh-cn/library/8kb3ddd4(VS.80).aspx
            //ddd 将一周中某天的缩写名称表示为当前 System.Globalization.DateTimeFormatInfo.AbbreviatedDayNames 属性中定义的名称。
        }

        /// <summary>
        ///A test for StringToDateTime
        ///</summary>
        [TestMethod()]
        public void ExpertDataTest()
        {
            TypedId rd = new TypedId("http://weibo.com/2394103717/xrAJIvkSQ");
            Assert.AreEqual(rd.type, WeiBeeCommon.Core.WeiBeeType.Sina);
            rd = new TypedId("http://t.qq.com/p/t/15673065427997");
            Assert.AreEqual(rd.type, WeiBeeCommon.Core.WeiBeeType.QQ);
            rd = new TypedId("http://t.sohu.com/m/2017731025");
            Assert.AreEqual(rd.type, WeiBeeCommon.Core.WeiBeeType.Sohu);
            Assert.AreEqual(rd.id, "2017731025");
        }

        [TestMethod()]
        public void RetweetActionManagerTest()
        {
            List<AuthEntity> entities = new List<AuthEntity>();
            entities.Add(new AuthEntity());
            var manager = RetweetActionManager.Instance(entities,"3456",null,"preat","afterat");
            Assert.IsNotNull(manager.GetJob());
            Thread.Sleep(5000);
            Assert.IsNotNull(manager.GetJob());
            Thread.Sleep(5000);
            Assert.IsFalse(string.IsNullOrEmpty(manager.GetJob().Status));
        }
    }
}
